// Purpose : This page is use for add topic.
// Date    : 28 August, 2007
// Author  : Vinayak Singh Rathore

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Text;

public partial class Community_Topics : System.Web.UI.Page
{
    char tabchar=' ';
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindList();
        }
        
    }

    /// <summary>
    /// This is event handler for Insert button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        
    }

   public void BindList()
    {
        Manager objManager = new Manager(true,"ConnectionString");
        if (Request.QueryString["tab"] != null)
        {
            tabchar = Convert.ToChar(Request.QueryString["tab"]);

            //dlistTopic.DataSource = objManager.ExecuteQuery("select id,Name from tbl_topics where Name like '" + tabchar + "%' and isdelete=0");
            dlistTopic.DataSource = objManager.ExecuteQuery("select id, Name as TopicName from tbl_topics where Name like '" + tabchar + "%' and isdelete=0");
            dlistTopic.DataBind();
        }
        else
        {
            //dlistTopic.DataSource = objManager.ExecuteQuery("select id ,Name from tbl_topics where id in (select top 10 topicid from forum order by postedon desc) and isdelete=0");
            dlistTopic.DataSource = objManager.ExecuteQuery("select top 10 t.id ,t.[Name] TopicName,(select count(id) from forum where topicid=t.id) as cnt from tbl_topics t where isDelete=0 order by cnt desc"); 
            dlistTopic.DataBind();
        }
        objManager = null;

    }
    protected void dlistTopic_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Go")
        {
            Response.Redirect("Forum.aspx?Id=" + e.CommandArgument);
        }
    }
}
